package me.chan.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class ReduceDemo {

	public static void main(String[] args) {
		
		List<Integer> intsList = Arrays.asList(1,2,3,4,5);
		/*Optional<Integer> sum = intsList.stream().reduce((a,b)-> a+b);
		if (sum.isPresent()) {
			System.out.println(sum.get());
		}*/
		//find the max number in the list
		intsList.stream().reduce(Integer::max).ifPresent(System.out::println);
		//find how many dishes on the menu
		Integer dishes = Dish.menu.stream().map(d -> 1).reduce(0, Integer::sum);
		long dishesInAnotherWay = Dish.menu.stream().count();
		System.out.println(dishes);
		System.out.println(dishesInAnotherWay);
	}

}
